package com.akujin.onemanga;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

public class pageView extends Activity {
	
	TextView selection;  
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //requestWindowFeature(Window.FEATURE_NO_TITLE);
        //getWindow().requestFeature(Window.FEATURE_PROGRESS);
        
		// Simplest usage: note that an exception will NOT be thrown
		// if there is an error loading this page (see below).
		if(OMservice.refreshPageImageURL()) {
			setURL(OMservice.currentPageURL);
		}
    }
    
    /* Creates the menu items */
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, 0, 0, "Prev Page").setIcon(android.R.drawable.ic_media_rew);
        menu.add(0, 1, 0, "Next Page").setIcon(android.R.drawable.ic_media_ff);
        return true;
    }

    /* Handles item selections */
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case 0:
            if(OMservice.refreshPrevPage()) {
            	setURL(OMservice.currentPageURL);
            }
            return true;
        case 1:
            if(OMservice.refreshNextPage()) {
            	setURL(OMservice.currentPageURL);
            }
            return true;
        }
        return false;
    }
    
    //private static final FrameLayout.LayoutParams ZOOM_PARAMS = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT,Gravity.BOTTOM);
    
    public void setURL(String url) {
    	WebView webview = new WebView(this);
    	
    	webview.getSettings().setBuiltInZoomControls(true);
    	webview.getSettings().setUseWideViewPort(true);
    	webview.setMapTrackballToArrowKeys(true);
    	webview.setInitialScale(25); //From API doc: 0 means default. If getUseWideViewPort() is true, it zooms out all the way
    	
    	/*
    	 * They only show up after clicking the map. This is true even if you use 
			mapView.displayZoomControls(true); 
			
			Only way I've found to prevent the controls from disappearing is by using
			undocumented getZoomButtonsController():
	    	mapView.getZoomButtonsController().setAutoDismissed(false);
			mapView.getZoomButtonsController().setVisible(true);
			webview.invokeZoomPicker(); //(too show it forcably after someone touches screen)
    	 */
    	
	    /*final Activity activity = this;
	    webview.setWebChromeClient(new WebChromeClient() {
	      public void onProgressChanged(WebView view, int progress) {
	        // Activities and WebViews measure progress with different scales.
	        // The progress meter will automatically disappear when we reach 100%
	        activity.setProgress(progress * 1000);
	      }
	    });*/
    	
		setContentView(webview);
		
		
		/*"file://sdcard/DCIM/Camera/1250058664828.jpg"*//*OMservice.url + OMservice.getCurrentPage()*/
		webview.loadData("<center><IMG SRC=\"" + url + "\" /></center>", "text/html",  "UTF-8");

		
		//webview.loadUrl(url);
    }

}
